package com.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.entity.Production;

@Repository
public class ProductionDAO extends BaseDAO<Production> {
	
	public ProductionDAO() {
		super(Production.class);
	}
	
	public List<Production> findByCategory(int categoryId, String orderBy){
		String hql = "where o.productCategory.id=?";
		if(orderBy != null &&!"".endsWith(orderBy)){
			hql = hql + " order by " + orderBy;
		}
		return this.findResultList(hql, categoryId);
	}
	
	public List<Production> findByCategoryInPage(int categoryId, String orderBy, int start, int limit){
		String hql = "where o.productCategory.id=?";
		if(orderBy != null &&!"".endsWith(orderBy)){
			hql = hql + " order by " + orderBy;
		}
		return this.findResultListInPage(hql, start, limit, categoryId);
	}
	
	public Long countByCategory(int categoryId){
		String hql = "where o.productCategory.id=?";
		Object result = this.findResultCount(hql, categoryId);
		if(result != null){
			return (Long) result;
		}
		return new Long(0);
	}
	
	public List<Production> findHotProduct(){
		return this.findByProperty(Production.IS_HOT, true, Production.INSERT_TIME);
	}
	
	public List<Production> findTopProduct(){
		return this.findByProperty(Production.IS_TOP, true, Production.INSERT_TIME);
	}

}
